﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DTO;
using Data;
namespace DAO
{
    public class NguyenLieu_DAO
    {
        public static List<NguyenLieu_DTO> SelectAll()
        {
            List<NguyenLieu_DTO> result = new List<NguyenLieu_DTO>();
            DataTable dt = Data.SQLAccess.ExecuteQuery("select *from NGUYEN_LIEU");
            DTO.NguyenLieu_DTO nguyen_lieu;
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                nguyen_lieu = new DTO.NguyenLieu_DTO();
                nguyen_lieu._Ma_Nguyen_Lieu = int.Parse(dt.Rows[i]["MA_NGUYEN_LIEU"].ToString());
                nguyen_lieu._Ma_Loai_Nguyen_Lieu = int.Parse(dt.Rows[i]["MA_LOAI_NGUYEN_LIEU"].ToString());
                nguyen_lieu._Ten_Nguyen_Lieu = dt.Rows[i]["TEN_NGUYEN_LIEU"].ToString();
                nguyen_lieu._Gia = float.Parse(dt.Rows[i]["GIA_TIEN"].ToString());
                nguyen_lieu._Ma_Nha_Cung_Cap = int.Parse(dt.Rows[i]["MA_NHA_CUNG_CAP"].ToString());
                result.Add(nguyen_lieu);
            }
            return result;
        }
        public static string Insert(NguyenLieu_DTO nguyen_lieu)
        {
            try
            {
                string str_sql = "insert into NGUYEN_LIEU values("
                + nguyen_lieu._Ma_Nguyen_Lieu + ","
                + nguyen_lieu._Ma_Loai_Nguyen_Lieu + ",'"
                + nguyen_lieu._Ten_Nguyen_Lieu + "',"
                + nguyen_lieu._Gia + ","
                + nguyen_lieu._Ma_Nha_Cung_Cap + ""
                + ")";
                DataTable dt = Data.SQLAccess.ExecuteQuery(str_sql);
                return "true";
            }
            catch (Exception ex)
            {
                return ex.ToString();
            }
        }
        public static string Delete(KhachHang_DTO khach_hang)
        {
            try
            {
                return "true";
            }
            catch (Exception ex)
            {
                return ex.ToString();
            }
        }
    }
}
